/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package service;

import Entity.Magasin;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.ws.rs.*;
import org.netbeans.saas.google.GoogleMapService;
import org.netbeans.saas.RestResponse;

/**
 *
 * @author Cyn
 */
@Stateless
@Path("entity.magasin")
public class MagasinFacadeREST extends AbstractFacade<Magasin> {

    @PersistenceContext(unitName = "WSemallAmazonPU")
    private EntityManager em;

    public MagasinFacadeREST() {
        super(Magasin.class);
    }

    @POST
    @Override
    @Consumes({"application/xml", "application/json"})
    public void create(Magasin entity) {
        super.create(entity);
    }

    @PUT
    @Override
    @Consumes({"application/xml", "application/json"})
    public void edit(Magasin entity) {
        super.edit(entity);
    }

    @DELETE
    @Path("{id}")
    public void remove(@PathParam("id") Long id) {
        super.remove(super.find(id));
    }

    @GET
    @Path("{id}")
    @Produces({"application/xml", "application/json"})
    public Magasin find(@PathParam("id") Long id) {
        return super.find(id);
    }

    @GET
    @Override
    @Produces({"application/xml", "application/json"})
    public List<Magasin> findAll() {
        return super.findAll();
    }

    @GET
    @Path("{from}/{to}")
    @Produces({"application/xml", "application/json"})
    public List<Magasin> findRange(@PathParam("from") Integer from, @PathParam("to") Integer to) {
        return super.findRange(new int[]{from, to});
    }

    @GET
    @Path("count")
    @Produces("text/plain")
    public String countREST() {
        return String.valueOf(super.count());
    }

    @java.lang.Override
    protected EntityManager getEntityManager() {
        return em;
    }

    @GET
    @Path("{address}")
    @Produces("text/html")
    public String getGoogleMap(@PathParam("address") String address) {

        try {
            //Magasin m = getEntityManager().find(Magasin.class, 1);
            //String address = m.getAdresse() + " " + m.getVille() + " " + m.getCodepostal();
            java.lang.Integer zoom = 15;
            String iframe = "false";

            RestResponse result = GoogleMapService.getGoogleMap(address, zoom, iframe);
            return result.getDataAsString();
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        return "";
    }
}
